package com.dkd.day20250615;

import com.dkd.day20250614.ListNode;

public class SolutiondeleteDuplicates {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(3);

        ListNode result = deleteDuplicates(head);
        while (result != null) {
            System.out.println(result.val);
            result = result.next;
        }

    }

    public static ListNode deleteDuplicates (ListNode head) {
        // write code here
        //非空和唯一判断
        if (head == null || head.next == null) {
            return head;
        }
        ListNode cur = head;
        System.out.println(cur.val);
        while (cur.next != null && cur!= null) {
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            }else{
                cur = cur.next;
            }
        }
        return head;
    }
}
